package com.bdb.myswipemultitype.bean;

import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bdb.myswipemultitype.R;
import com.bdb.myswipemultitype.swipeListview.swipeMenuRecycle.SwipeProvider;

/**
 * Created by zinc on 2017/5/15.
 */

public class ItemProvider extends SwipeProvider<ItemBean> {

    @Override
    protected int getContentLayoutId() {
        return R.layout.view_list_item;
    }

    @Override
    protected void onBindSwipeViewHolder(@NonNull final ViewHolder viewHolder, @NonNull final View view, @NonNull final ItemBean itemBean) {

        TextView textView = (TextView) view.findViewById(R.id.text_data);
        textView.setText(itemBean.getName());

        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linear_layout);

        Object tag = viewHolder.itemView.getTag(R.integer.itemListener);

        View.OnClickListener itemClick = null;

        if(tag != null){

            Log.i("itemClick", "old");
            itemClick = (View.OnClickListener) tag;

        }else{

            Log.i("itemClick", "new");
            itemClick = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(view.getContext(), itemBean.getName(), Toast.LENGTH_SHORT).show();
                }
            };
            viewHolder.itemView.setTag(R.integer.itemListener, itemClick);
        }

        linearLayout.setOnClickListener(itemClick);

    }

    @Override
    protected String getMenuName() {
        return "测试";
    }

    @Override
    protected int getMenuBgColor() {
        return R.color.colorPrimary;
    }

    @Override
    protected int getMenuColor() {
        return R.color.progress_bar_color;
    }
}
